<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#375EAB">

  <title>mycobra - Go Documentation Server</title>

<link type="text/css" rel="stylesheet" href="mycobra%20-%20Go%20Documentation%20Server_files/style.css">

<script>window.initFuncs = [];</script>
<script src="mycobra%20-%20Go%20Documentation%20Server_files/jquery.js" defer="defer"></script>



<script>var goVersion = "go1.15.2";</script>
<script src="mycobra%20-%20Go%20Documentation%20Server_files/godocs.js" defer="defer"></script>
</head>
<body>

<div id="lowframe" style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
...
</div><!-- #lowframe -->

<div id="topbar" class="wide"><div class="container">
<div class="top-heading" id="heading-wide"><a href="http://localhost:6060/pkg/">Go Documentation Server</a></div>
<div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/pkg/">GoDoc</a></div>
<a href="#" id="menu-button"><span id="menu-button-arrow">▽</span></a>
<form method="GET" action="/search">
<div id="menu" style="min-width: 60px;">

<span class="search-box"><input type="search" id="search" name="q" placeholder="Search" aria-label="Search" required=""><button type="submit"><span><!-- magnifying glass: --><svg width="24" height="24" viewBox="0 0 24 24"><title>submit search</title><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path><path d="M0 0h24v24H0z" fill="none"></path></svg></span></button></span>
</div>
</form>

</div></div>



<div id="page" class="wide" style="outline: currentcolor none 0px;" tabindex="-1">
<div class="container">


  <h1>
    Package mycobra
    <span class="text-muted"></span>
  </h1>







<div id="nav"></div>


<!--
	Copyright 2009 The Go Authors. All rights reserved.
	Use of this source code is governed by a BSD-style
	license that can be found in the LICENSE file.
-->
<!--
	Note: Static (i.e., not template-generated) href and id
	attributes start with "pkg-" to make it impossible for
	them to conflict with generated attributes (some of which
	correspond to Go identifiers).
-->

	<script>
	document.ANALYSIS_DATA = null;
	document.CALLGRAPH = null;
	</script>

	
		
		<div id="short-nav">
			<dl>
			<dd><code>import "gitee.com/forblank/mycobra"</code></dd>
			</dl>
			<dl>
			<dd><a href="#pkg-overview" class="overviewLink">Overview</a></dd>
			<dd><a href="#pkg-index" class="indexLink">Index</a></dd>
			
			
			</dl>
		</div>
		<!-- The package's Name is printed as title by the top-level template -->
		<div id="pkg-overview" class="toggleVisible">
			<div class="collapsed">
				<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
			</div>
			<div class="expanded">
				<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
				<p>
Package mycobra 实现简化版 cobra 库, 支持带子命令的命令行程序开发
</p>

				
			</div>
		</div>

		<div id="pkg-index" class="toggleVisible">
		<div class="collapsed">
			<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
		</div>
		<div class="expanded">
			<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>

		<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
			<div id="manual-nav">
			<dl>
			
			
			
			
				
				<dd><a href="#Command">type Command</a></dd>
				
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.AddCommand">func (cmd *Command) AddCommand(subCmds ...*Command)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.Execute">func (cmd *Command) Execute() error</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.Find">func (cmd *Command) Find(args []string) (*Command, []string, error)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.HelpFunc">func (cmd *Command) HelpFunc() func(*Command, []string)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.InitDefaultHelpCmd">func (cmd *Command) InitDefaultHelpCmd()</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.Name">func (cmd *Command) Name() string</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.RemoveCommand">func (cmd *Command) RemoveCommand(rmCmds ...*Command)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.Root">func (cmd *Command) Root() *Command</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.Runnable">func (cmd *Command) Runnable() bool</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.SetHelpCommand">func (cmd *Command) SetHelpCommand(c *Command)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Command.SetHelpFunc">func (cmd *Command) SetHelpFunc(f func(*Command, []string))</a></dd>
				
			
			
			</dl>
			</div><!-- #manual-nav -->

		

		
			<h3>Package files</h3>
			<p>
			<span style="font-size:90%">
			
				<a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go">command.go</a>
			
				<a href="http://localhost:6060/src/gitee.com/forblank/mycobra/help.go">help.go</a>
			
			</span>
			</p>
		
		</div><!-- .expanded -->
		</div><!-- #pkg-index -->

		

		
		
		
		
			
			
			<h2 id="Command">type <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go?s=344:1524#L5">Command</a>
				<a class="permalink" href="#Command">¶</a>
				
				
			</h2>
			<p>
Command 结构定义了应用程序所使用的命令.
使用者应该在命令定义中自定义用法和描述, 以确保可用性.
</p>

			<pre>type Command struct {

<span id="Command.Use"></span>    <span class="comment">// Use 描述使用方法的单行信息.</span>
    <span class="comment">// 推荐语法如下:</span>
    <span class="comment">//   [ ] 标识一个可选参数，未在 [ ] 中的参数是必需的.</span>
    <span class="comment">//   ... 表示可以为前一个参数指定多个值.</span>
    <span class="comment">//   |   表示互斥，可以使用 | 左侧或右侧的参数, 但不能在一条命令中同时使用两个参数.</span>
    <span class="comment">//   { } 分隔一组互斥的参数.</span>
    <span class="comment">// Example: add [-F file | -D dir]... [-f format] profile</span>
    Use <a href="http://localhost:6060/pkg/builtin/#string">string</a>

<span id="Command.Short"></span>    <span class="comment">// Short 在 'help' 中输出的短描述.</span>
    Short <a href="http://localhost:6060/pkg/builtin/#string">string</a>

<span id="Command.Long"></span>    <span class="comment">// Long 在 'help &lt;this-command&gt;' 中输出的长描述.</span>
    Long <a href="http://localhost:6060/pkg/builtin/#string">string</a>

<span id="Command.Run"></span>    <span class="comment">// Run 运行命令, 大多命令只需要实现这个函数.</span>
    Run func(cmd *<a href="#Command">Command</a>, args []<a href="http://localhost:6060/pkg/builtin/#string">string</a>)

<span id="Command.RunE"></span>    <span class="comment">// RunE 运行命令并返回错误.</span>
    RunE func(cmd *<a href="#Command">Command</a>, args []<a href="http://localhost:6060/pkg/builtin/#string">string</a>) <a href="http://localhost:6060/pkg/builtin/#error">error</a>
    <span class="comment">// contains filtered or unexported fields</span>
}
</pre>

			

			

			
			
			

			

			
				
				<h3 id="Command.AddCommand">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go?s=3859:3910#L132">AddCommand</a>
					<a class="permalink" href="#Command.AddCommand">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) AddCommand(subCmds ...*<a href="#Command">Command</a>)</pre>
				<p>
AddCommand 为该父命令增加子命令.
</p>

				
				
				
			
				
				<h3 id="Command.Execute">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go?s=1557:1592#L45">Execute</a>
					<a class="permalink" href="#Command.Execute">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) Execute() <a href="http://localhost:6060/pkg/builtin/#error">error</a></pre>
				<p>
Execute 执行该命令.
</p>

				
				
				
			
				
				<h3 id="Command.Find">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go?s=2661:2728#L89">Find</a>
					<a class="permalink" href="#Command.Find">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) Find(args []<a href="http://localhost:6060/pkg/builtin/#string">string</a>) (*<a href="#Command">Command</a>, []<a href="http://localhost:6060/pkg/builtin/#string">string</a>, <a href="http://localhost:6060/pkg/builtin/#error">error</a>)</pre>
				<p>
Find 根据输入参数寻找要执行的子命令, 剩余参数作为 flags 返回.
</p>

				
				
				
			
				
				<h3 id="Command.HelpFunc">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/help.go?s=92:147#L1">HelpFunc</a>
					<a class="permalink" href="#Command.HelpFunc">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) HelpFunc() func(*<a href="#Command">Command</a>, []<a href="http://localhost:6060/pkg/builtin/#string">string</a>)</pre>
				<p>
HelpFunc 返回自身或父函数或默认 helpFunc.
</p>

				
				
				
			
				
				<h3 id="Command.InitDefaultHelpCmd">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/help.go?s=1051:1091#L28">InitDefaultHelpCmd</a>
					<a class="permalink" href="#Command.InitDefaultHelpCmd">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) InitDefaultHelpCmd()</pre>
				<p>
InitDefaultHelpCmd 为该命令增加 help 子命令.
如果该命令没有子命令或者已经有 help 子命令, 那么将什么都不做.
</p>

				
				
				
			
				
				<h3 id="Command.Name">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go?s=4556:4589#L159">Name</a>
					<a class="permalink" href="#Command.Name">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) Name() <a href="http://localhost:6060/pkg/builtin/#string">string</a></pre>
				<p>
Name 返回 Command.Use 字段首单词作为该命令的名字.
</p>

				
				
				
			
				
				<h3 id="Command.RemoveCommand">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go?s=4164:4217#L143">RemoveCommand</a>
					<a class="permalink" href="#Command.RemoveCommand">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) RemoveCommand(rmCmds ...*<a href="#Command">Command</a>)</pre>
				<p>
RemoveCommand 从该父命令中删除子命令.
</p>

				
				
				
			
				
				<h3 id="Command.Root">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go?s=4731:4766#L169">Root</a>
					<a class="permalink" href="#Command.Root">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) Root() *<a href="#Command">Command</a></pre>
				<p>
Root 返回 root 根命令.
</p>

				
				
				
			
				
				<h3 id="Command.Runnable">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/command.go?s=2485:2520#L84">Runnable</a>
					<a class="permalink" href="#Command.Runnable">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) Runnable() <a href="http://localhost:6060/pkg/builtin/#bool">bool</a></pre>
				<p>
Runnable 确定命令本身是否可运行.
</p>

				
				
				
			
				
				<h3 id="Command.SetHelpCommand">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/help.go?s=1850:1896#L55">SetHelpCommand</a>
					<a class="permalink" href="#Command.SetHelpCommand">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) SetHelpCommand(c *<a href="#Command">Command</a>)</pre>
				<p>
SetHelpCommand 设置该命令的 helpCommand 为用户自定义 helpCommand.
</p>

				
				
				
			
				
				<h3 id="Command.SetHelpFunc">func (*Command) <a href="http://localhost:6060/src/gitee.com/forblank/mycobra/help.go?s=814:873#L22">SetHelpFunc</a>
					<a class="permalink" href="#Command.SetHelpFunc">¶</a>
					
					
				</h3>
				<pre>func (cmd *<a href="#Command">Command</a>) SetHelpFunc(f func(*<a href="#Command">Command</a>, []<a href="http://localhost:6060/pkg/builtin/#string">string</a>))</pre>
				<p>
SetHelpFunc 设置该命令的 helpFunc 为用户自定义 helpFunc.
</p>

				
				
				
			
		
	

	







<div id="footer">
Build version go1.15.2.<br>
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
<a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
</div>

</div><!-- .container -->
</div><!-- #page -->


</body></html>